home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / uupc11ys.zip / LIB / CHDIR.C < prev    next >
C/C++ Source or Header  |  1992-11-27  |  3KB  |  89 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    c h d i r . c                                                   */
  3. /*                                                                    */
  4. /*    Support routines for UUPC/extended                              */
  5. /*                                                                    */
  6. /*    Changes Copyright 1990, 1991 (c) Andrew H. Derbyshire           */
  7. /*                                                                    */
  8. /*    History:                                                        */
  9. /*       21Nov1991 Break out of lib.c                          ahd    */
  10. /*--------------------------------------------------------------------*/
  11.  
  12. #include <ctype.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include <time.h>
  17.  
  18. #ifndef __GNUC__
  19. #include <dos.h>
  20. #include <direct.h>
  21. #endif
  22.  
  23. /*--------------------------------------------------------------------*/
  24. /*                    UUPC/extended include files                     */
  25. /*--------------------------------------------------------------------*/
  26.  
  27. #include "lib.h"
  28. #include "hlib.h"
  29.  
  30. static int changedir( const char *path);
  31.  
  32. /*--------------------------------------------------------------------*/
  33. /*    C H D I R                                                       */
  34. /*                                                                    */
  35. /*    Like chdir() but create the directory if necessary              */
  36. /*--------------------------------------------------------------------*/
  37.  
  38. int CHDIR(const char *path)
  39. {
  40.  
  41.    if (*path == '\0')
  42.       return 0;
  43.  
  44. /*--------------------------------------------------------------------*/
  45. /*        Try to change directories, returning if successfull         */
  46. /*--------------------------------------------------------------------*/
  47.  
  48.    if (!changedir( path ))
  49.       return 0;
  50.  
  51. /*--------------------------------------------------------------------*/
  52. /*                      Try making the directory                      */
  53. /*--------------------------------------------------------------------*/
  54.  
  55.    MKDIR(path);
  56.  
  57.    /* change to last directory */
  58.    return changedir(path);
  59.  
  60. } /*CHDIR*/
  61.  
  62. /*--------------------------------------------------------------------*/
  63. /*    c h a n g e d i r                                               */
  64. /*                                                                    */
  65. /*    Like chdir() but also changes the current drive                 */
  66. /*--------------------------------------------------------------------*/
  67.  
  68. static int changedir(const char *path)
  69. {
  70.  
  71.    if ((*path != '\0') && (path[1] == ':')) {
  72.       unsigned char drive = (unsigned char) toupper(*path);
  73.       if ((drive >= 'A') && (drive <= 'Z'))
  74.       {
  75. #ifdef __TURBOC__
  76.          setdisk(drive - (unsigned char)'A');
  77. #else
  78.          if (_chdrive( drive - (unsigned char)'A' + 1))  /* MS C     */
  79.             return -1;                 /* Return if failure          */
  80. #endif
  81.       } /* if */
  82.       else
  83.          return -1;
  84.    }
  85.  
  86.    return chdir(path);
  87.  
  88. } /*changedir*/
  89.